package com.cadre.web.controller.officer;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cadre.common.enums.ConferenceStateEnum;
import com.cadre.common.utils.R;
import com.cadre.common.utils.SecurityUtils;
import com.cadre.common.utils.common.DateUtils;
import com.cadre.common.utils.common.GenerateUUID;
import com.cadre.common.utils.oldutil.AgeUtil;
import com.cadre.common.utils.oldutil.DateUtil;
import com.cadre.common.utils.oldutil.DesUtilNet;
import com.cadre.common.utils.oldutil.PageUtils;
import com.cadre.system.domain.officer.*;
import com.cadre.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

@Api(tags = {"A-N上会管理-上会人员名单"})
@RequestMapping({"/profess/confernamelist_n"})
@RestController
/* loaded from: NEWConfernamelistController.class */
public class NEWConfernamelistController {
    @Autowired
    private NEWConfernamelistService confernamelistService;
    @Autowired
    private NEWBatchconferenceService batchconferenceService;
    @Autowired
    private A01Service a01Service;
    @Resource
    private A19Service a19Service;
    @Autowired
    private NEWPostchangeService postchangeService;
    @Autowired
    private PptService pptSer;

    @PostMapping({"/getList"})
    @ApiOperation("部会管理--新增名单获取列表")
    public R getList(@RequestParam Map<String, Object> param) {
        if (param.get("submissdept") == null) {
            param.put("submissdept", SecurityUtils.getDeptId());
        }
        if (param.get("submissdept").equals("admin")) {
            param.remove("submissdept");
        }
        return R.ok().put("list", (Object) this.confernamelistService.getListByBatchId(param));
    }

    @PostMapping({"/getListByBatchId"})
    @ApiOperation("获取批次人员名单列表")
    public R getListByBatchId(@RequestParam Map<String, Object> param) {
        if (param.get("submissdept") == null) {
            param.put("submissdept", SecurityUtils.getDeptId());
        }
        if (param.get("submissuser") == null) {
            param.put("submissuser", SecurityUtils.getUserId());
        }
        if (param.get("submissdept").equals("admin")) {
            param.remove("submissdept");
        }
        return R.ok().put("list", (Object) this.confernamelistService.getListByBatchId(param));
    }

    @PostMapping({"/getListAll"})
    @ApiOperation("常会获取未汇总名单")
    public R getListAll() {
        return R.ok().put("list", (Object) this.confernamelistService.getListAll());
    }

    @PostMapping({"/getListForOften/{id}"})
    @ApiOperation("根据常会批次获取上常会名单")
    public R getListForOften(@PathVariable("id") String oftenbatchid) {
        return R.ok().put("list", (Object) this.confernamelistService.getListForOften(oftenbatchid));
    }

    @RequestMapping({"/info/{flowid}"})
    public R info(@PathVariable("flowid") String flowid) {
        return R.ok().put("confernamelist", (Object) ((ConfernamelistEntity) this.confernamelistService.getById(flowid)));
    }

    @PostMapping({"/saveList/{batchId}"})
    @Transactional
    @ApiOperation("部务会---添加人员---确定")
    public R saveList(@PathVariable("batchId") String batchId, @RequestBody ConfernamelistEntity[] confernamelistEntity_arr) {
        int maxSort = this.confernamelistService.selectMaxSort(batchId);
        for (int i = 0; i < confernamelistEntity_arr.length; i++) {
            ConfernamelistEntity c = confernamelistEntity_arr[i];
            c.setSubmissdept(SecurityUtils.getDeptId());
            c.setSubmissuser(SecurityUtils.getUserId());
            A01 a = (A01) this.a01Service.getById(c.getPersonid());
            if (a != null) {
                c.setA0101(formatName(a));
                c.setA0106b(getA0106b(a));
                c.setA0180b(getA0180B(a));
                c.setA0108b(getA0108B(a.getA0108()));
            }
            c.setResult(ConferenceStateEnum.NOT_SUBMITED.getValue());
            c.setSort(Integer.valueOf(maxSort + i + 1));
            LambdaQueryWrapper<ConfernamelistEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            if (this.confernamelistService.getBaseMapper().selectList(lambdaQueryWrapper.eq(ConfernamelistEntity::getBatchid, batchId).
                    eq(ConfernamelistEntity::getPersonid, c.getPersonid())).size() == 0) {
                this.confernamelistService.save(c);
                Map<String, Object> map = new HashMap<>();
                map.put("personid", c.getPersonid());
                map.put("a1935", 1);
                for (A19 a19 : this.a19Service.selectByList(map)) {
                    PostchangeEntity p = setPostChange(a19);
                    p.setNamelistid(batchId);
                    p.setSubmissdept(SecurityUtils.getDeptId());
                    this.postchangeService.save(p);
                }
            }
        }
        return R.ok();
    }

    @PostMapping({"/saveList_n/{batchId}"})
    @Transactional
    @ApiOperation("编辑添加人员---确定")
    public R saveList_n(@PathVariable("batchId") String batchId, @RequestBody ConfernamelistEntity[] confernamelistEntity_arr) {
        int maxSort = this.confernamelistService.selectMaxSort(batchId);
        for (int i = 0; i < confernamelistEntity_arr.length; i++) {
            ConfernamelistEntity c = confernamelistEntity_arr[i];
            A01 a = (A01) this.a01Service.getById(c.getPersonid());
            if (a != null) {
                c.setA0101(formatName(a));
                c.setA0106b(getA0106b(a));
                c.setA0180b(getA0180B(a));
                c.setA0108b(getA0108B(a.getA0108()));
            }
            c.setSubmissdept(SecurityUtils.getDeptId());
            c.setSubmissuser(SecurityUtils.getUserId());
            c.setResult(ConferenceStateEnum.SUBMITED.getValue());
            c.setSort(Integer.valueOf(maxSort + i + 1));
            LambdaQueryWrapper<ConfernamelistEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            if (this.confernamelistService.getBaseMapper().selectList(lambdaQueryWrapper.eq(ConfernamelistEntity::getBatchid, batchId).
                    eq(ConfernamelistEntity::getPersonid, c.getPersonid())).size() == 0) {
                this.confernamelistService.save(c);
                Map<String, Object> map = new HashMap<>();
                map.put("personid", c.getPersonid());
                map.put("a1935", 1);
                for (A19 a19 : this.a19Service.selectByList(map)) {
                    try {
                        PostchangeEntity p = setPostChange(a19);
                        p.setNamelistid(batchId);
                        p.setSubmissdept(SecurityUtils.getDeptId());
                        this.postchangeService.save(p);
                    } catch (Exception ex) {
                        System.out.println("====>" + a19.toString() + "insert error:" + ex.getMessage());
                    }
                }
            }
        }
        return R.ok();
    }

    private String formatName(A01 a01) {
        StringBuilder sb = new StringBuilder();
        String name = a01.getA0101();
        if (name.length() == 2) {
            name = name.replaceAll("(\\S)", "$0 ");
        }
        String sex = a01.getA0105() == null ? "男" : a01.getA0105();
        String nation = a01.getA0130() == null ? "汉族" : a01.getA0130();
        if (sex.equals("男") && !nation.equals("汉族")) {
            sb.append(name).append("\n(").append(nation).append(")");
            return sb.toString();
        } else if (!sex.equals("男") && nation.equals("汉族")) {
            sb.append(name).append("\n(").append(sex).append(")");
            return sb.toString();
        } else if (sex.equals("男") || nation.equals("汉族")) {
            sb.append(name);
            return sb.toString();
        } else {
            sb.append(name).append("\n(").append(sex).append("、").append(nation).append(")");
            return sb.toString();
        }
    }

    @PostMapping({"/saveListForyichu/{batchId}"})
    @Transactional
    public R saveListForyichu(@PathVariable("batchId") String batchId, @RequestBody ConfernamelistEntity[] confernamelistEntity_arr) {
        for (ConfernamelistEntity c : confernamelistEntity_arr) {
            c.setSubmissdept(SecurityUtils.getDeptId());
            c.setResult(ConferenceStateEnum.SUBMITED.getValue());
            LambdaQueryWrapper<ConfernamelistEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            List<ConfernamelistEntity> list = this.confernamelistService.getBaseMapper().selectList(lambdaQueryWrapper.
                    eq(ConfernamelistEntity::getBatchid, batchId).eq(ConfernamelistEntity::getPersonid, c.getPersonid()));
            if (list.size() > 0) {
                return R.error("error");
            }
            if (list.size() == 0) {
                this.confernamelistService.save(c);
                Map<String, Object> map = new HashMap<>();
                map.put("personid", c.getPersonid());
                map.put("a1935", 1);
                for (A19 a19 : this.a19Service.selectByList(map)) {
                    PostchangeEntity p = setPostChange(a19);
                    p.setNamelistid(batchId);
                    this.postchangeService.save(p);
                }
            }
        }
        return R.ok();
    }

    private PostchangeEntity setPostChange(A19 a19) {
        PostchangeEntity p = new PostchangeEntity();
        p.setA19flowid(a19.getFlowid());
        p.setA1905(a19.getA1905());
        p.setA1910(a19.getA1910());
        p.setA1915(a19.getA1915());
        p.setA1916(a19.getA1916());
        p.setA1920(a19.getA1920());
        p.setA1925(a19.getA1925());
        p.setA1930(a19.getA1930());
        p.setA1935(a19.getA1935());
        p.setA1940(a19.getA1940());
        p.setA1945(a19.getA1945());
        p.setA1950(a19.getA1950());
        p.setA1955(a19.getA1955());
        p.setA1956(a19.getA1956());
        p.setA1960(a19.getA1960());
        p.setA1965(a19.getA1965());
        p.setA1970(a19.getA1970());
        p.setPersonid(a19.getPersonid());
        p.setRemark(a19.getRemark());
        p.setSort(a19.getSort());
        p.setSerial(a19.getSerial());
        p.setFlag(a19.getA1935());
        return p;
    }

    @PostMapping({"/saveBatch/{name}"})
    @Transactional
    @ApiOperation("上报名单管理-保存按钮")
    public R saveBatch(@PathVariable("name") String name) {
        Long deptId = SecurityUtils.getDeptId();
        String id = GenerateUUID.getUUID();
        BatchconferenceEntity b = new BatchconferenceEntity();
        b.setFlowid(id);
        b.setName(name);
        b.setUnitid(String.valueOf(deptId));
        b.setStata(ConferenceStateEnum.NOT_SUMMARIZED.getValue());
        b.setType("0");
        b.setCreatetime(new Date());
        this.batchconferenceService.save(b);
        LambdaQueryWrapper<ConfernamelistEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        for (ConfernamelistEntity confernamelistEntity : this.confernamelistService.getBaseMapper().selectList(lambdaQueryWrapper.
                eq(ConfernamelistEntity::getBatchid, "-1").eq(ConfernamelistEntity::getSubmissdept, String.valueOf(deptId)))) {
            confernamelistEntity.setBatchid(id);
            confernamelistEntity.setResult(ConferenceStateEnum.SUBMITED.getValue());
            this.confernamelistService.updateById(confernamelistEntity);
        }
        LambdaQueryWrapper<PostchangeEntity> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
        for (PostchangeEntity p : this.postchangeService.getBaseMapper().selectList(lambdaQueryWrapper1.
                eq(PostchangeEntity::getNamelistid, "-1").eq(PostchangeEntity::getSubmissdept, String.valueOf(deptId)))) {
            p.setNamelistid(id);
            this.postchangeService.updateById(p);
        }
        return R.ok();
    }

    @PostMapping({"/updateList/{batchId}"})
    @Transactional
    @ApiOperation("部务会议--名单管理--编辑拟任拟免--保存操作")
    public R updateList(@PathVariable("batchId") String batchId, @RequestBody ConfernamelistEntity[] confernamelistEntity_arr) {
        if (null == confernamelistEntity_arr || confernamelistEntity_arr.length < 1) {
            return R.error("请选择上会人员");
        }
        for (ConfernamelistEntity c : confernamelistEntity_arr) {
            c.setInputtype("0");
            this.confernamelistService.updateById(c);
        }
        return R.ok().put("name", (Object) this.batchconferenceService.getMeetName());
    }

    @RequestMapping({"/update"})
    public R update(@RequestBody ConfernamelistEntity confernamelist) {
        confernamelist.setInputtype("1");
        this.confernamelistService.updateById(confernamelist);
        return R.ok();
    }

    @PostMapping({"/submitForOften"})
    @Transactional
    @ApiOperation("提交常委会")
    public R submitForOften(@RequestBody ConfernamelistEntity[] confernamelistEntity_arr) {
        if (null == confernamelistEntity_arr || confernamelistEntity_arr.length < 1) {
            return R.error("参数错误");
        }
        LambdaQueryWrapper<ConfernamelistEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<ConfernamelistEntity> entities = this.confernamelistService.getBaseMapper().selectList(lambdaQueryWrapper.
                eq(ConfernamelistEntity::getBatchid, Arrays.asList(confernamelistEntity_arr).get(0).getBatchid()));
        if (!CollectionUtils.isNotEmpty(entities)) {
            return R.error("批次号错误");
        }
        if (((List) entities.stream().map((v0) -> {
            return v0.getOftenresult();
        }).collect(Collectors.toList())).contains(ConferenceStateEnum.OFTEN_SUBMITED.getValue())) {
            return R.error("该部委会已提交至常委会，无法重复提交");
        }
        if (CollectionUtils.isNotEmpty((List) entities.stream().filter(c -> {
            return c.getOftenbatchid() != null;
        }).collect(Collectors.toList()))) {
            return R.error("该部委会已提交至常委会，无法重复提交");
        }
        for (ConfernamelistEntity entity : confernamelistEntity_arr) {
            entity.setOftenresult(ConferenceStateEnum.OFTEN_SUBMITED.getValue());
            this.confernamelistService.updateById(entity);
        }
        return R.ok();
    }

    @Transactional
    @GetMapping({"/batchupdate"})
    @ApiOperation("批量更新批次名单表")
    public R batchupdate(@RequestBody ConfernamelistEntity[] confernamelistEntity_arr, String batchId) {
        for (ConfernamelistEntity entity : confernamelistEntity_arr) {
            this.confernamelistService.updateById(entity);
        }
        BatchconferenceEntity batchconference = (BatchconferenceEntity) this.batchconferenceService.getById(batchId);
        batchconference.setStata(ConferenceStateEnum.TO_BE_ATTENDED.getValue());
        this.batchconferenceService.updateById(batchconference);
        return R.ok();
    }

    @GetMapping({"/returnNameList"})
    @ApiOperation("退回")
    public R returnNameList(String batchId, String dept) {
        LambdaQueryWrapper<ConfernamelistEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<ConfernamelistEntity> list = this.confernamelistService.getBaseMapper().selectList(lambdaQueryWrapper.
                eq(ConfernamelistEntity::getBatchid, batchId).eq(ConfernamelistEntity::getSubmissdept, dept));
        list.forEach(t -> {
            t.setResult(ConferenceStateEnum.NOT_SUBMITED.getValue());
        });
        for (ConfernamelistEntity entity : list) {
            this.confernamelistService.updateById(entity);
        }
        return R.ok();
    }

    @GetMapping({"/tabmenu"})
    @ApiOperation("干部处室上人员上报动态标签卡")
    public R tabmenu(String batchid) {
        return R.ok().put("data", (Object) this.confernamelistService.tabmenu(batchid));
    }

    @PostMapping({"/delete"})
    @ApiOperation("上报名单管理---删除人员")
    public R delete(@RequestBody String[] flowids) {
        for (String str : flowids) {
            LambdaQueryWrapper<PostchangeEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            ConfernamelistEntity v = (ConfernamelistEntity) this.confernamelistService.getById(str);
            this.postchangeService.remove(lambdaQueryWrapper.eq(PostchangeEntity::getNamelistid, v.getBatchid()).eq(PostchangeEntity::getPersonid, v.getPersonid()));
        }
        this.confernamelistService.removeBatchByIds(Arrays.asList(flowids));
        return R.ok();
    }

    @PostMapping({"recall/{batchId}"})
    @ApiOperation("撤回")
    public R recall(@PathVariable String batchId) {
        List<ConfernamelistEntity> list = this.confernamelistService.getConfernamelist(batchId, SecurityUtils.getDeptId());
        for (int i = 0; i < list.size(); i++) {
            ConfernamelistEntity c = list.get(i);
            c.setResult(ConferenceStateEnum.NOT_SUBMITED.getValue());
            this.confernamelistService.updateById(c);
        }
        return R.ok();
    }

    @GetMapping({"addSubmit"})
    @ApiOperation("添加人员---确定--返回页面数据查询")
    public R addSubmit(@RequestBody String[] personids) {
        LambdaQueryWrapper<A01> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        return R.ok().put("list", (Object) this.a01Service.getBaseMapper().selectList(lambdaQueryWrapper.
                select(A01::getA0101,A01::getA0183,A01::getA0185,A01::getA0180,A01::getA0106,A01::getA0108,A01::getA0136,
                        A01::getA0184,A01::getA0187,A01::getA0188,A01::getA0190,A01::getA0191).in(A01::getFlowid, personids)));
    }

    @PostMapping({"/personSort"})
    @ApiOperation("名单表排序")
    public R personSort(@RequestBody ConfernamelistEntity[] confernamelistEntity_arr) {
        for (ConfernamelistEntity entity : confernamelistEntity_arr) {
            this.confernamelistService.updateById(entity);
        }
        return R.ok();
    }

    @PostMapping({"/updateByIdPass/{type}"})
    @ApiOperation("修改Confernamelist通过")
    public R updateByIdPass(@RequestBody String[] ids, @PathVariable("type") String type) {
        if (ids.length == 0) {
            return R.error();
        }
        ConfernamelistEntity c = (ConfernamelistEntity) this.confernamelistService.getById(ids[0]);
        if ("1".equals(type)) {
            this.confernamelistService.updateResultByBathid(c.getBatchid(), ConferenceStateEnum.NOT_PASS.getValue());
        } else if ("2".equals(type)) {
            this.confernamelistService.updateOftenresultByOftenbatchid(c.getOftenbatchid(), ConferenceStateEnum.NOT_PASS.getValue());
        }
        for (String str : ids) {
            ConfernamelistEntity confernamelistEntity = (ConfernamelistEntity) this.confernamelistService.getById(str);
            if (type != null) {
                if ("1".equals(type)) {
                    confernamelistEntity.setResult(ConferenceStateEnum.PASS.getValue());
                } else if ("2".equals(type)) {
                    confernamelistEntity.setOftenresult(ConferenceStateEnum.PASS.getValue());
                }
            }
            this.confernamelistService.updateByPrimaryKeySelective(confernamelistEntity);
        }
        return R.ok();
    }

    @PostMapping({"/updateByIdNoPass/{type}"})
    @ApiOperation("修改Confernamelist不通过")
    public R updateByIdNoPass(@RequestBody String[] ids, @PathVariable("type") String type) {
        if (ids.length == 0) {
            return R.error();
        }
        for (String str : ids) {
            ConfernamelistEntity confernamelistEntity = (ConfernamelistEntity) this.confernamelistService.getById(str);
            if (type != null) {
                if ("1".equals(type)) {
                    confernamelistEntity.setResult(ConferenceStateEnum.NOT_PASS.getValue());
                } else if ("2".equals(type)) {
                    confernamelistEntity.setOftenresult(ConferenceStateEnum.NOT_PASS.getValue());
                }
            }
            this.confernamelistService.updateByPrimaryKeySelective(confernamelistEntity);
        }
        return R.ok();
    }

    @PostMapping({"/saveListForOften/{batchId}"})
    @Transactional
    @ApiOperation("常会添加人员---确定")
    public R saveListForOften(@PathVariable("batchId") String batchId, @RequestBody ConfernamelistEntity[] confernamelistEntity_arr) {
        int MaxOftenSort = this.confernamelistService.selectMaxOftenSort(batchId);
        for (int i = 0; i < confernamelistEntity_arr.length; i++) {
            ConfernamelistEntity c = confernamelistEntity_arr[i];
            A01 a = (A01) this.a01Service.getById(c.getPersonid());
            if (a != null) {
                c.setA0106b(getA0106b(a));
                c.setA0180b(getA0180B(a));
                c.setA0108b(getA0108B(a.getA0108()));
            }
            c.setSubmissdept(SecurityUtils.getDeptId());
            c.setResult(ConferenceStateEnum.NOT_SUBMITED.getValue());
            c.setOftenbatchid(batchId);
            c.setOftensort(Integer.valueOf(MaxOftenSort + i + 1));
            LambdaQueryWrapper<ConfernamelistEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
            if (this.confernamelistService.getBaseMapper().selectList(lambdaQueryWrapper.
                    eq(ConfernamelistEntity::getOftenbatchid, batchId).eq(ConfernamelistEntity::getPersonid, c.getPersonid()).
                    eq(ConfernamelistEntity::getBatchid, batchId)).size() == 0) {
                this.confernamelistService.save(c);
                Map<String, Object> map = new HashMap<>();
                map.put("personid", c.getPersonid());
                map.put("a1935", 1);
                for (A19 a19 : this.a19Service.selectByList(map)) {
                    PostchangeEntity p = setPostChange(a19);
                    p.setNamelistid(batchId);
                    p.setSubmissdept(SecurityUtils.getDeptId());
                    this.postchangeService.save(p);
                }
            }
        }
        return R.ok();
    }

    @PostMapping({"/deleteForOften"})
    @ApiOperation("上报名单管理---删除人员")
    public R deleteForOften(@RequestBody String[] flowids) {
        this.confernamelistService.updateOftenbatchId("", flowids);
        return R.ok();
    }

    @RequestMapping(value = {"/list"}, method = {RequestMethod.POST})
    @ApiOperation("人员列表")
    public R list(@RequestParam Map<String, Object> map) {
        return R.ok().put("page", (Object) this.confernamelistService.selectListByName(map));
    }

    @GetMapping({"/getA01Value"})
    @ApiOperation("获取A01某列值")
    public R getA01Value(@RequestParam String personId, @RequestParam String column) {
        String s = "";
        if (column != null && personId != null && !column.equals("removepost") && !column.equals("assumepost")) {
            Object obj = this.confernamelistService.getA01Value(personId, column);
            if (column.equals("a0185") || column.equals("a0106") || column.equals("a0180") || column.equals("a0184") || column.equals("a0138")) {
                if (obj != null) {
                    try {
                        s = new SimpleDateFormat(DateUtil.MONTG_DATE_FORMAT).format((Date) obj);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            } else if (obj != null) {
                s = obj.toString();
            }
        }
        return R.ok().put("value", (Object) s);
    }

    private String getA0180B(A01 a01) {
        Map<String, String> map = new HashMap<>();
        map.put("省部级正职", "正省");
        map.put("省部级副职", "副省");
        map.put("厅局级正职", "正厅");
        map.put("厅局级副职", "副厅");
        map.put("县处级正职", "正处");
        map.put("县处级副职", "副处");
        map.put("比照正厅级", "正厅");
        map.put("比照副厅级", "副厅");
        map.put("比照正处级", "正处");
        map.put("一级巡视员", "一巡");
        map.put("二级巡视员", "二巡");
        map.put("一级调研员", "一调");
        map.put("二级调研员", "二调");
        map.put("三级调研员", "三调");
        map.put("四级调研员", "四调");
        map.put("乡科级正职", "正科");
        map.put("乡科级副职", "副科");
        StringBuilder sb = new StringBuilder();
        if (a01.getA0180() != null) {
            sb.append(DateUtils.format(a01.getA0180(), DateUtil.MONTG_DATE_FORMAT)).append("\n");
        }
        if (!(a01.getA0179() == null || a01.getA0179().equals("") || map.get(a01.getA0179()) == null)) {
            sb.append(map.get(a01.getA0179())).append("\n");
        }
        if (a01.getA0142() != null) {
            sb.append(DateUtils.format(a01.getA0142(), DateUtil.MONTG_DATE_FORMAT)).append("\n");
        }
        if (!(a01.getA0198() == null || a01.getA0198().equals("") || map.get(a01.getA0198()) == null)) {
            sb.append(map.get(a01.getA0198()));
        }
        return sb.toString();
    }

    private String getA0106b(A01 a01) {
        Date a0106 = a01.getA0106();
        if (a0106 == null) {
            return "";
        }
        int age = AgeUtil.getCurrentAge(a0106);
        String time = new SimpleDateFormat(DateUtil.MONTG_DATE_FORMAT).format(a0106);
        return time + "\n(" + age + ")";
    }

    private String getA0108B(String a0108) {
        if (a0108 == null || a0108 == "") {
            return "";
        }
        if (a0108.contains("内蒙古") || a0108.contains("黑龙江")) {
            return a0108.substring(0, 3) + "\n" + a0108.substring(3, a0108.length());
        }
        return a0108.substring(0, 2) + "\n" + a0108.substring(2, a0108.length());
    }

    @PostMapping({"/getListForType"})
    @ApiOperation("获取未同步人员")
    public R getListForType(@RequestParam Map<String, Object> map) {
        int type = Integer.parseInt(map.get("type").toString());
        int pageSize = 15;
        int pageNum = 1;
        if (map.get("pageSize") != null) {
            pageSize = Integer.parseInt((String) map.get("pageSize"));
        }
        if (map.get("pageNum") != null) {
            pageNum = Integer.parseInt((String) map.get("pageNum"));
        }
        if (type == 0) {
            List<Archives> list = this.confernamelistService.getListForMeetBW();
            return R.ok().put("page", (Object) new PageUtils(list, list.size(), pageSize, pageNum));
        }
        List<Archives> list2 = this.confernamelistService.getListForMeetCW();
        return R.ok().put("page", (Object) new PageUtils(list2, list2.size(), pageSize, pageNum));
    }

    @PostMapping({"/getSynchroYList"})
    @ApiOperation("获取已同步人员")
    public R getSynchroYList(@RequestParam Map<String, Object> map) {
        int pageSize = 15;
        int pageNum = 1;
        if (map.get("pageSize") != null) {
            pageSize = Integer.parseInt((String) map.get("pageSize"));
        }
        if (map.get("pageNum") != null) {
            pageNum = Integer.parseInt((String) map.get("pageNum"));
        }
        List<Archives> list = this.confernamelistService.getSynchroYList();
        return R.ok().put("page", (Object) new PageUtils(list, list.size(), pageSize, pageNum));
    }

    @GetMapping({"/getDataForDex/{flowid}"})
    @ApiOperation("获取Des加密数据")
    public R getDataForDex(@PathVariable("flowid") String flowid) {
        String jobunit = "";
        String icard = "";
        String name = "";
        String appointtime = "";
        new DesUtilNet();
        System.out.println(flowid);
        Map<String, Object> map = new HashMap<>();
        map.put("personid", flowid);
        map.put("a1935", 1);
        List<A19> listA19 = this.a19Service.selectByList(map);
        StringBuffer strb = new StringBuffer();
        for (int i = 0; i < listA19.size(); i++) {
            if (listA19.get(i).getA1916() == null || listA19.get(i).getA1916().equals("")) {
                strb.append(";");
            } else {
                strb.append(listA19.get(i).getA1916() + ";");
            }
            if (listA19.get(i).getA1920() == null || listA19.get(i).getA1920().equals("")) {
                strb.append(";");
            } else {
                strb.append(listA19.get(i).getA1920() + ";");
            }
        }
        System.out.println(strb.toString());
        try {
            jobunit = DesUtilNet.GetBase64Str(DesUtilNet.encrypt(strb.toString()));
        } catch (Exception e) {
            e.printStackTrace();
        }
        A01 a = (A01) this.a01Service.getById(flowid);
        if (a.getA0101() != null && !a.getA0101().equals("")) {
            try {
                name = DesUtilNet.GetBase64Str(DesUtilNet.encrypt(a.getA0101()));
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        if (a.getA0107() != null && !a.getA0107().equals("")) {
            try {
                icard = DesUtilNet.GetBase64Str(DesUtilNet.encrypt(a.getA0107()));
            } catch (Exception e3) {
                e3.printStackTrace();
            }
        }
        if (a.getA0185() != null) {
            try {
                appointtime = DesUtilNet.GetBase64Str(DesUtilNet.encrypt(new SimpleDateFormat("yyyyMM").format(a.getA0185())));
            } catch (Exception e4) {
                e4.printStackTrace();
            }
        }
        System.out.println("<<<<<<<<<<<" + jobunit);
        return R.ok().put("name", (Object) name).put("icard", (Object) icard).put("appointtime", (Object) appointtime).put("jobunit", (Object) jobunit);
    }

    @GetMapping({"/updateSynchroState/{cid}"})
    @ApiOperation("获取Des加密数据")
    public R updateSynchroState(@PathVariable("cid") String cid) {
        ConfernamelistEntity c = (ConfernamelistEntity) this.confernamelistService.getById(cid);
        c.setSynchrostate("已同步");
        c.setSynchrodate(new Date());
        this.confernamelistService.updateById(c);
        return R.ok();
    }

    @PostMapping({"/ppt"})
    @ApiImplicitParam(name = "ids", value = "人员id", required = true, paramType = "query")
    @ApiOperation("上会任免报表：导出上会任免报表ppt")
    public void exportPpt(String ids, String batchId, String flag, HttpServletResponse httpServletResponse) {
        List<String> listNow = new ArrayList<>();
        List<Map<String, Object>> listMap = new ArrayList<>();
        List<A01> list = this.confernamelistService.selectA01ListByPerSonIds(listNow, batchId, flag);
        SimpleDateFormat df = new SimpleDateFormat(DateUtil.MONTG_DATE_FORMAT);
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                Map<String, Object> map = new HashMap<>();
                if (isNull(list.get(i).getA0101())) {
                    String a0101 = list.get(i).getA0101();
                    if (a0101.indexOf("\n") > -1) {
                        map.put("name", a0101.substring(0, a0101.indexOf("\n")));
                    } else {
                        map.put("name", a0101);
                    }
                } else {
                    map.put("name", "");
                }
                if (list.get(i).getA0171() != null) {
                    map.put("zp", list.get(i).getA0171());
                } else {
                    map.put("zp", new byte[10]);
                }
                StringBuffer sb = new StringBuffer();
                if (list.get(i).getA0101() == null || list.get(i).getA0101().trim().equals("")) {
                    sb.append("");
                } else {
                    sb.append(list.get(i).getA0101() + ",");
                }
                if (list.get(i).getA0105() == null || list.get(i).getA0105().trim().equals("") || !list.get(i).getA0105().equals("女")) {
                    sb.append("");
                } else {
                    sb.append(list.get(i).getA0105() + ",");
                }
                if (list.get(i).getA0130() == null || list.get(i).getA0130().trim().equals("") || list.get(i).getA0130().equals("汉族")) {
                    sb.append("");
                } else {
                    sb.append(list.get(i).getA0130() + ",");
                }
                if (list.get(i).getA0106() != null) {
                    sb.append(df.format(list.get(i).getA0106()) + "生,");
                }
                if (isNull(list.get(i).getA0108())) {
                    sb.append(list.get(i).getA0108() + "人,");
                }
                if (isNull(list.get(i).getA0187())) {
                    sb.append("全日制" + list.get(i).getA0187());
                    if (!isNull(list.get(i).getA0188())) {
                        sb.append(",");
                    }
                }
                if (isNull(list.get(i).getA0188())) {
                    sb.append("  (" + list.get(i).getA0188() + "),");
                }
                if (isNull(list.get(i).getA0192())) {
                    sb.append(list.get(i).getA0192() + "。");
                }
                if (list.get(i).getA0180() != null) {
                    sb.append(df.format(list.get(i).getA0180()) + "任现职。");
                }
                if (list.get(i).getA0177b() != null) {
                    String[] strArr = list.get(i).getA0177b().replaceAll(" ", "").replaceAll("\n\r|\r\n|\n", "\r").split("\r");
                    for (String string : strArr) {
                        if (string.length() > 0) {
                            sb.append(string + "\n");
                        }
                    }
                }
                if (sb.length() > 1) {
                    map.put("grjj", sb.toString());
                } else {
                    map.put("grjj", " ");
                }
                if (isNull(list.get(i).getA0183())) {
                    map.put("xr", "现任：" + list.get(i).getA0183());
                } else {
                    map.put("xr", "现任：");
                }
                if (isNull(list.get(i).getNrzw())) {
                    map.put("nr", "拟任：" + list.get(i).getNrzw());
                } else {
                    map.put("nr", "拟任：");
                }
                if (isNull(list.get(i).getNmzw())) {
                    map.put("nm", "拟免：" + list.get(i).getNmzw());
                } else {
                    map.put("nm", "拟免：");
                }
                if (isNull(list.get(i).getA0196())) {
                    map.put("kc", list.get(i).getA0196().toString());
                } else {
                    map.put("kc", " ");
                }
                listMap.add(map);
            }
            this.pptSer.inputDataForPptType2(listMap, list.size(), httpServletResponse);
        }
    }

    private boolean isNull(String str) {
        if (str == null || str.trim().equals("")) {
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        new DesUtilNet();
        try {
            String jobunit = DesUtilNet.encrypt2("副师职射击长;省人大监察和司法委员会;原煤井副总工长;大同市人大常委会;党委书记;大同市人大常委会;法律顾问;省人大监察和司法委员会;", "HXYZDATA");
            System.out.println(jobunit);
            System.out.println(DesUtilNet.decrypt2(jobunit, "HXYZDATA"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
